//
//  LoginAndRegisterViewController.m
//  Comma
//
//  Created by liuchang on 15/1/16.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "LoginAndRegisterViewController.h"
#import "NDetailListViewController.h"
#import "CollegeRegisterViewController.h"
#import "URLMacro.h"
#import "GlobalMethod.h"
#import "AFNetWorkingYU.h"
#import "SSKeychain.h"
#import "YRSideViewController.h"
#import "ResetPasswordView.h"
#import "ConfirmResetView.h"
#import "NavigationViewController.h"
#import "LoadIndicator.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "VPImageCropperViewController.h"
#import "UpLoadMyPhoto.h"
#import "AppDelegate.h"
/*注册页面右按钮的frame*/
#define REGIST_RIGHT_X _registView.rightUpButton.frame.origin.x
#define REGIST_RIGHT_Y _registView.rightUpButton.frame.origin.y
#define REGIST_RIGHT_WIDTH _registView.rightUpButton.frame.size.width
#define REGIST_RIGHT_HEIGHT _registView.rightUpButton.frame.size.height

/*登录页面右按钮的frame*/
#define LOGIN_RIGHT_X _loginView.rightUpButton.frame.origin.x
#define LOGIN_RIGHT_Y _loginView.rightUpButton.frame.origin.y
#define LOGIN_RIGHT_WIDTH _loginView.rightUpButton.frame.size.width
#define LOGIN_RIGHT_HEIGHT _loginView.rightUpButton.frame.size.height

/*注册页面下方按钮的frame*/
#define REGIST_DOWN_X _registView.centerDownButton.frame.origin.x
#define REGIST_DOWN_Y _registView.centerDownButton.frame.origin.y
#define REGIST_DOWN_WIDTH _registView.centerDownButton.frame.size.width
#define REGIST_DOWN_HEIGHT _registView.centerDownButton.frame.size.height

/*登录页面下方按钮的frame*/
#define LOGIN_DOWN_X _loginView.centerDownButton.frame.origin.x
#define LOGIN_DOWN_Y _loginView.centerDownButton.frame.origin.y
#define LOGIN_DOWN_WIDTH _loginView.centerDownButton.frame.size.width
#define LOGIN_DOWN_HEIGHT _loginView.centerDownButton.frame.size.height

/*注册身份页面的左按钮的frame*/
#define IDENTITY_LEFT_X _identity.leftUpButton.frame.origin.x
#define IDENTITY_LEFT_Y _identity.leftUpButton.frame.origin.y
#define IDENTITY_LEFT_WIDTH _identity.leftUpButton.frame.size.width
#define IDENTITY_LEFT_HEIGHT _identity.leftUpButton.frame.size.height

/*注册身份页面的下方进入按钮的frame*/
#define IDENTITY_DOWN_X _identity.centerDownButton.frame.origin.x
#define IDENTITY_DOWN_Y _identity.centerDownButton.frame.origin.y
#define IDENTITY_DOWN_WIDTH _identity.centerDownButton.frame.size.width
#define IDENTITY_DOWN_HEIGHT _identity.centerDownButton.frame.size.height

#define ORIGINAL_MAX_WIDTH 640.0f
@interface LoginAndRegisterViewController ()<VPImageCropperDelegate>
{
    NSInteger _timeCount;
    NSTimer  *_timer;
}

@end

@implementation LoginAndRegisterViewController

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"IDENTITY" object:nil];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.load = [[LoadIndicator alloc] init];
        
        // 学生类型默认为"学生", "男"
        self.student = @"学生";
        self.sex = @"男";
        
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getIdentityType:) name:@"IDENTITY" object:nil];
    }
    return self;
}

- (void)loadView
{
    [super loadView];
    self.mainView = [[MainView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.view = self.mainView;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    // 主视图
    [self createLoginAndRegister];
    [self createLoginView];
    [self createRegistView];
    [self createIdentityRegistView];
    [self createCollegeRegist];
    [self createResetPassWord];
    [self createConfirmReset];
    
    [self.mainView bringSubviewToFront:_loginAndRegister];
    
    // 选择相册和头像按钮点击事件
    [_mainView.album addTarget:self action:@selector(pickImageFromAlbum) forControlEvents:UIControlEventTouchUpInside];
    [_mainView.camera addTarget:self action:@selector(pickImageFromCamera) forControlEvents:UIControlEventTouchUpInside];
    
    // 创建调用相机&相册imagePickerController
    self.imagePicker = [[UIImagePickerController alloc] init];
    
    AppDelegate *appdel = (AppDelegate *)[UIApplication sharedApplication].delegate;
    appdel.window.rootViewController.view.hidden = NO;
    
}

#pragma mark - 创建login&register视图
- (void)createLoginAndRegister
{
    self.loginAndRegister = [[LoginAndRegister alloc] initWithLeftUpButton:nil rightUpButton:nil upTextField:nil centerTextField:nil downTextField:nil upButton:nil centerButton:nil downButton:nil centerDownButton:nil];
    self.loginAndRegister.frame = CGRectMake(0, SCREEN_HEIGHT * 0.6 - 88, SCREEN_WIDTH, SCREEN_HEIGHT - (SCREEN_HEIGHT * 0.6 - 88));
    if (iPhone6Plus) {
        _loginAndRegister.frame = CGRectMake(0, SCREEN_HEIGHT * 0.6 - 132, SCREEN_WIDTH, SCREEN_HEIGHT - (SCREEN_HEIGHT * 0.6 - 132));
    }
    [_loginAndRegister createLoginButton];
    [_loginAndRegister createRegisterButton];
    
    [_loginAndRegister.registButton addTarget:self action:@selector(registAndLoginAction:) forControlEvents:UIControlEventTouchUpInside];
    [_loginAndRegister.loginButton addTarget:self action:@selector(registAndLoginAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.mainView addSubview:_loginAndRegister];
    
    
}

#pragma mark - 创建login视图
- (void)createLoginView
{
    self.loginView = [[LoginView alloc] initWithLeftUpButton:nil rightUpButton:@"注册 >" upTextField:@"手机号" centerTextField:@"密码" downTextField:nil upButton:nil centerButton:@"忘记密码?" downButton:nil centerDownButton:@"登录"];
    // 自定义控件的frame
    [self.loginView changeControlType];
    
    // 为跳转注册按钮添加点击事件
    [_loginView.rightUpButton addTarget:self action:@selector(registButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 为登录按钮添加点击事件
    [_loginView.centerButton addTarget:self action:@selector(centerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 忘记密码
    [_loginView.centerDownButton addTarget:self action:@selector(loginEnterAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 添加视图到主视图上的右侧
    [self.mainView addSubview:_loginView];
}

#pragma mark - 创建register视图
- (void)createRegistView
{
    self.registView = [[RegisterView alloc] initWithLeftUpButton:nil rightUpButton:@"登录 >" upTextField:@"手机号" centerTextField:@"密  码" downTextField:@"验证码" upButton:nil centerButton:nil downButton:@"发送验证码 >" centerDownButton:@"下一步"];
    
    // 手动创建密码明示按钮
    [_registView createCenterButtonWithTitle:nil];
    
    // 自定义控件的frame
    [_registView changeControlType];
    
    // 为跳转登录按钮添加点击事件
    [_registView.rightUpButton addTarget:self action:@selector(loginButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 下一步按钮点击事件
    [_registView.centerDownButton addTarget:self action:@selector(nextPageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 发送验证码按钮点击事件
    [_registView.downButton addTarget:self action:@selector(verifyButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 添加视图到主视图上的右侧
    [self.mainView addSubview:_registView];
}

#pragma mark - 创建选择身份页面
- (void)createIdentityRegistView
{
    self.identity = [[IdentityRegisterView alloc] initWithLeftUpButton:nil rightUpButton:nil upTextField:@"学  校" centerTextField:@"姓  名" downTextField:nil upButton:nil centerButton:nil downButton:nil centerDownButton:@"进入"];    
    // 创建学生类型, 性别
    [_identity createStudentAndSexButton];
    _identity.upTextField.delegate = self;
    
    // 为 "进入" 按钮添加点击事件
    [_identity.centerDownButton addTarget:self action:@selector(transferMyDataToServer:) forControlEvents:UIControlEventTouchUpInside];
    
    // 将整个界面放到主视图的右侧
    [self.mainView addSubview:_identity];
    
}

#pragma mark - 创建学校选择页面
- (void)createCollegeRegist
{
    self.collegeRegist = [[CollegeRegisterViewController alloc] init];
    self.collegeRegist.delegate = self;
}

#pragma mark - 忘记密码

- (void)createConfirmReset
{
    self.confirmReset = [[ConfirmResetView alloc] initWithLeftUpButton:nil rightUpButton:nil upTextField:nil centerTextField:nil downTextField:nil upButton:nil centerButton:@"确认" downButton:nil centerDownButton:nil];
    [_confirmReset addCustomUI];
    [_confirmReset.centerButton addTarget:self action:@selector(confirmResetCenterButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.mainView addSubview:_confirmReset];
}

- (void)createResetPassWord
{
    self.resetPassword = [[ResetPasswordView alloc] initWithLeftUpButton:nil rightUpButton:nil upTextField:@"手机号" centerTextField:@"新密码" downTextField:@"重复密码" upButton:nil centerButton:@"取消" downButton:@"获取验证码" centerDownButton:@"下一步"];
    _resetPassword.upTextField.keyboardType = UIKeyboardTypeNumberPad;
    _resetPassword.centerTextField.secureTextEntry = YES;
    _resetPassword.downTextField.secureTextEntry = YES;
    [_resetPassword addCustomUI];
    _resetPassword.auTextField.keyboardType = UIKeyboardTypeNumberPad;
    [self.resetPassword.downButton addTarget:self action:@selector(resetDownButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.resetPassword.centerButton addTarget:self action:@selector(centerDownButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.resetPassword.centerDownButton addTarget:self action:@selector(resetPasswordCenterDownAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.mainView addSubview:_resetPassword];
    
}

#pragma mark - 首页登录&注册选择按钮点击事件
- (void)registAndLoginAction:(UIButton *)button
{
    // 不管点击注册还是登录按钮, 视图向左移动
    [self beginAnimationWithView:self.loginAndRegister.registButton delay:0 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:self.loginAndRegister.line delay:0.03 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:self.loginAndRegister.loginButton delay:0.06 distance:-SCREEN_WIDTH];
    _loginView.centerDownLine.backgroundColor = LINEERGRAY;
    // 讲底部的线显示出来
    if (button.tag == 1) {
        [self.mainView bringSubviewToFront:_registView];
        // 点击了注册按钮, 注册界面飞出来
        _registView.rightUpButton.frame = CGRectMake(REGIST_RIGHT_X - SCREEN_WIDTH, REGIST_RIGHT_Y, REGIST_RIGHT_WIDTH, REGIST_RIGHT_HEIGHT);
        [self beginAnimationWithView:_registView.upTextField delay:0.3 distance:-SCREEN_WIDTH];
        [self beginAnimationWithView:_registView.upLine delay:0.33 distance:-SCREEN_WIDTH];
        [self beginAnimationWithView:_registView.centerTextField delay:0.36 distance:-SCREEN_WIDTH];
        [self beginAnimationWithView:_registView.downLine delay:0.39 distance:-SCREEN_WIDTH];
        [self beginAnimationWithView:_registView.downTextField delay:0.42 distance:-SCREEN_WIDTH];
        [self beginAnimationWithView:_registView.centerButton delay:0.36 distance:-SCREEN_WIDTH];
        [self beginAnimationWithView:_registView.downButton delay:0.45 distance:-SCREEN_WIDTH];
        self.registView.centerDownButton.frame = CGRectMake(REGIST_DOWN_X - SCREEN_WIDTH, REGIST_DOWN_Y, REGIST_DOWN_WIDTH, REGIST_DOWN_HEIGHT); 
        
    } else if (button.tag == 2) {
        [self.mainView bringSubviewToFront:_loginView];
        
        // 点击登录, 各控件移动动画
        _loginView.rightUpButton.frame = CGRectMake(LOGIN_RIGHT_X - SCREEN_WIDTH, LOGIN_RIGHT_Y, LOGIN_RIGHT_WIDTH, LOGIN_RIGHT_HEIGHT);
        [self beginAnimationWithView:_loginView.upTextField delay:0.3 distance:-SCREEN_WIDTH];
        [self beginAnimationWithView:_loginView.lineView delay:0.33 distance:-SCREEN_WIDTH];
        [self beginAnimationWithView:_loginView.centerTextField delay:0.36 distance:-SCREEN_WIDTH];
        [self beginAnimationWithView:_loginView.centerButton delay:0.39 distance:-SCREEN_WIDTH];
        self.loginView.centerDownButton.frame = CGRectMake(LOGIN_DOWN_X - SCREEN_WIDTH, LOGIN_DOWN_Y, LOGIN_DOWN_WIDTH, LOGIN_DOWN_HEIGHT);
    }
}

#pragma mark - 点击注册切换到注册页面
- (void)registButtonAction:(UIButton *)button
{
    [self.mainView bringSubviewToFront:_registView];
    // 设置将要出来的控件的原始位置
    _registView.rightUpButton.frame = CGRectMake(SCREEN_WIDTH - 57 + SCREEN_WIDTH, 0, 41, 44);
    _registView.upTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 44, SCREEN_WIDTH - 110, 44);
    _registView.upLine.frame = CGRectMake(SCREEN_WIDTH, 88, SCREEN_WIDTH, 0.5);
    _registView.centerTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 88, SCREEN_WIDTH - 110, 44);
    _registView.downLine.frame = CGRectMake(SCREEN_WIDTH, 132, SCREEN_WIDTH, 0.5);
    _registView.downTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 132, SCREEN_WIDTH - 110, 44);
    _registView.centerButton.frame = CGRectMake(SCREEN_WIDTH - 51 + SCREEN_WIDTH, 88, 44, 44);
    _registView.downButton.frame = CGRectMake(SCREEN_WIDTH - 98 + SCREEN_WIDTH, 132, 83, 44);
    _registView.centerDownButton.frame = CGRectMake(SCREEN_WIDTH / 2 - 50 + SCREEN_WIDTH, SCREEN_HEIGHT * 0.24 + 44, 100, 44);
    
    // 登录页面的控件向左出去
    _loginView.rightUpButton.frame = CGRectMake(LOGIN_RIGHT_X - SCREEN_WIDTH, LOGIN_RIGHT_Y, LOGIN_RIGHT_WIDTH, LOGIN_RIGHT_HEIGHT);
    [self beginAnimationWithView:_loginView.upTextField delay:0 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.lineView delay:0.03 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerTextField delay:0.06 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerButton delay:0.09 distance:-SCREEN_WIDTH];
    self.loginView.centerDownButton.frame = CGRectMake(LOGIN_DOWN_X - SCREEN_WIDTH, LOGIN_DOWN_Y, LOGIN_DOWN_WIDTH, LOGIN_DOWN_HEIGHT);   
    
    // 注册页面的控件出现
    _registView.rightUpButton.frame = CGRectMake(REGIST_RIGHT_X - SCREEN_WIDTH, REGIST_RIGHT_Y, REGIST_RIGHT_WIDTH, REGIST_RIGHT_HEIGHT);
    [self beginAnimationWithView:_loginView.rightUpButton delay:0.3 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.upTextField delay:0.3 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.upLine delay:0.33 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.centerTextField delay:0.36 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.downLine delay:0.39 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.downTextField delay:0.42 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.centerButton delay:0.36 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.downButton delay:0.45 distance:-SCREEN_WIDTH];
    self.registView.centerDownButton.frame = CGRectMake(REGIST_DOWN_X - SCREEN_WIDTH, REGIST_DOWN_Y, REGIST_DOWN_WIDTH, REGIST_DOWN_HEIGHT);   
    
}

#pragma mark - 点击登录切换到登录界面
- (void)loginButtonAction:(UIButton *)button
{
    [self.mainView bringSubviewToFront:_loginView];
    _loginView.rightUpButton.frame = CGRectMake(SCREEN_WIDTH - 57 + SCREEN_WIDTH, 0, 41, 44);
    _loginView.upTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 44, SCREEN_WIDTH - 110, 44);
    _loginView.lineView.frame = CGRectMake(SCREEN_WIDTH, 88, SCREEN_WIDTH, 0.5);
    _loginView.centerTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 88, SCREEN_WIDTH - 110, 44);
    _loginView.centerButton.frame = CGRectMake(SCREEN_WIDTH - 80 + SCREEN_WIDTH, 88, 65, 44);
    _loginView.centerDownButton.frame = CGRectMake(SCREEN_WIDTH / 2 - 50 + SCREEN_WIDTH, SCREEN_HEIGHT * 0.24 + 44, 100, 44);
    
    // 注册界面的控件向左出去
    _registView.rightUpButton.frame = CGRectMake(REGIST_RIGHT_X - SCREEN_WIDTH, REGIST_RIGHT_Y, REGIST_RIGHT_WIDTH, REGIST_RIGHT_HEIGHT);
    [self beginAnimationWithView:_registView.upTextField delay:0 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.upLine delay:0.03 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.centerTextField delay:0.06 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.downLine delay:0.09 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.downTextField delay:0.12 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.centerButton delay:0.06 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.downButton delay:0.15 distance:-SCREEN_WIDTH];
    self.registView.centerDownButton.frame = CGRectMake(REGIST_DOWN_X - SCREEN_WIDTH, REGIST_DOWN_Y, REGIST_DOWN_WIDTH, REGIST_DOWN_HEIGHT);   
    
    // 登录界面的控件显示
    _loginView.rightUpButton.frame = CGRectMake(LOGIN_RIGHT_X - SCREEN_WIDTH, LOGIN_RIGHT_Y, LOGIN_RIGHT_WIDTH, LOGIN_RIGHT_HEIGHT);
    [self beginAnimationWithView:_loginView.upTextField delay:0.3 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.lineView delay:0.33 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerTextField delay:0.36 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerButton delay:0.39 distance:-SCREEN_WIDTH];
    self.loginView.centerDownButton.frame = CGRectMake(LOGIN_DOWN_X - SCREEN_WIDTH, LOGIN_DOWN_Y, LOGIN_DOWN_WIDTH, LOGIN_DOWN_HEIGHT);   
    
}

#pragma mark - 找回密码点击事件

#pragma mark - 找回密码验证码
- (void)resetDownButtonAction:(id)sender
{
    self.phoneNumber = self.resetPassword.upTextField.text;
    // 将参数存入字典
    NSMutableDictionary *parmeters = [self getParmeterDic];
    // 获得拼接后的参数字符串
    NSString *body = [self getFullParmeterWithDic:parmeters];
    // 发送请求
    [AFNetWorkingYU netWorkWithURL:@"http://www.isu.so/sms_api/req" body:body resultBlock:^(id result) {
        NSDictionary *resultDic = (NSDictionary *)result;
        NSString *msg = [resultDic objectForKey:@"msg"];
        if ([msg isEqualToString:@"success"]) {
            // 倒计时
            _timeCount = 45;
            _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(resetCountDown) userInfo:nil repeats:YES];
        } else {
            [self showAlertWithMessage:msg];
            
        }
        
    }];
}

#pragma mark - 取消找回密码
- (void)centerDownButtonAction:(id)sender
{
    [self.mainView endEditing:YES];
    _loginView.rightUpButton.frame = CGRectMake(SCREEN_WIDTH - 57 + SCREEN_WIDTH, 0, 41, 44);
    // 注册页面的控件出现
    _resetPassword.rightUpButton.frame = CGRectMake(REGIST_RIGHT_X - SCREEN_WIDTH, REGIST_RIGHT_Y, REGIST_RIGHT_WIDTH, REGIST_RIGHT_HEIGHT);
    [UIView animateWithDuration:0.15 animations:^{
        [self.mainView.iconView setAlpha:0];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.15 animations:^{
            [self.mainView.imgView setAlpha:1];
        }];
    }];
    
    [self beginAnimationWithView:_resetPassword.upTextField delay:0.0f distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.upLine delay:0.03f distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.centerTextField delay:0.06 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.midLine delay:0.09 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.downTextField delay:0.12 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.downLine delay:0.12 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.auTextField delay:0.13 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.downButton delay:0.13 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.centerButton delay:0.18 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.centerDownButton delay:0.18 distance:SCREEN_WIDTH];
    
    // 登录页面的控件向右出去
    _loginView.rightUpButton.frame = CGRectMake(LOGIN_RIGHT_X - SCREEN_WIDTH, LOGIN_RIGHT_Y, LOGIN_RIGHT_WIDTH, LOGIN_RIGHT_HEIGHT);
    //    [self beginAnimationWithView:self.mainView.imgView delay:0.3 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.upTextField delay:0.3 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.lineView delay:0.33 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerTextField delay:0.36 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerButton delay:0.39 distance:SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerDownButton delay:0.39 distance:SCREEN_WIDTH];
    [self.mainView sendSubviewToBack:_resetPassword];
    
}

#pragma mark - 忘记密码
- (void)centerButtonAction:(id)sender
{
    [self.mainView bringSubviewToFront:_resetPassword];
    _resetPassword.upTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 0, SCREEN_WIDTH - 110, 44);
    _resetPassword.upLine.frame = CGRectMake(SCREEN_WIDTH, 44, SCREEN_WIDTH, 0.5);
    _resetPassword.centerTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 44, SCREEN_WIDTH - 110, 44);
    _resetPassword.midLine.frame = CGRectMake(SCREEN_WIDTH, 88, SCREEN_WIDTH, 0.5);
    _resetPassword.downTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 88, SCREEN_WIDTH - 110, 44);
    _resetPassword.downLine.frame = CGRectMake(SCREEN_WIDTH, 132, SCREEN_WIDTH, 0.5);
    _resetPassword.auTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 132, SCREEN_WIDTH - 110, 44);
    _resetPassword.downButton.frame = CGRectMake(SCREEN_WIDTH - 99 + SCREEN_WIDTH, 132, 100, 44);
    _resetPassword.centerDownButton.frame = CGRectMake(SCREEN_WIDTH / 2 - 50 + SCREEN_WIDTH, SCREEN_HEIGHT * 0.24 + 44, 100, 44);
    _resetPassword.centerButton.frame = CGRectMake(SCREEN_WIDTH / 2 - 50 + SCREEN_WIDTH, _resetPassword.centerDownButton.frame.origin.y + _resetPassword.centerDownButton.frame.size.height, 100, 44);
    
    _resetPassword.downButton.frame = CGRectMake(SCREEN_WIDTH - 99 + SCREEN_WIDTH, 132, 83, 44);
    
    // 登录页面的控件向左出去
    _loginView.rightUpButton.frame = CGRectMake(LOGIN_RIGHT_X - SCREEN_WIDTH, LOGIN_RIGHT_Y, LOGIN_RIGHT_WIDTH, LOGIN_RIGHT_HEIGHT);
    //    [self beginAnimationWithView:self.mainView.imgView delay:0 distance:-SCREEN_WIDTH];
    [UIView animateWithDuration:0.15 animations:^{
        [self.mainView.imgView setAlpha:0];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.15 animations:^{
            [self.mainView.iconView setAlpha:1];
        }];
    }];
    [self beginAnimationWithView:_loginView.upTextField delay:0 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.lineView delay:0.03 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerTextField delay:0.06 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerButton delay:0.09 distance:-SCREEN_WIDTH];
    self.loginView.centerDownButton.frame = CGRectMake(LOGIN_DOWN_X - SCREEN_WIDTH, LOGIN_DOWN_Y, LOGIN_DOWN_WIDTH, LOGIN_DOWN_HEIGHT);
    
    _resetPassword.rightUpButton.frame = CGRectMake(REGIST_RIGHT_X - SCREEN_WIDTH, REGIST_RIGHT_Y, REGIST_RIGHT_WIDTH, REGIST_RIGHT_HEIGHT);
    //    [self beginAnimationWithView:self.mainView.iconView delay:0.3 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.upTextField delay:0.3 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.upLine delay:0.33 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.centerTextField delay:0.36 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.midLine delay:0.39 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.downTextField delay:0.42 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.downLine delay:0.42 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.auTextField delay:0.45 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.downButton delay:0.45 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.centerButton delay:0.48 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_resetPassword.centerDownButton delay:0.48 distance:-SCREEN_WIDTH];
}

#pragma mark - 确认更改密码
- (void)confirmResetCenterButtonAction:(id)sender
{
    [self.mainView bringSubviewToFront:_loginView];
    _loginView.rightUpButton.frame = CGRectMake(SCREEN_WIDTH - 57 + SCREEN_WIDTH, 0, 41, 44);
    _loginView.upTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 44, SCREEN_WIDTH - 110, 44);
    _loginView.lineView.frame = CGRectMake(SCREEN_WIDTH, 88, SCREEN_WIDTH, 0.5);
    _loginView.centerTextField.frame = CGRectMake(16 + SCREEN_WIDTH, 88, SCREEN_WIDTH - 110, 44);
    _loginView.centerButton.frame = CGRectMake(SCREEN_WIDTH - 80 + SCREEN_WIDTH, 88, 65, 44);
    _loginView.centerDownButton.frame = CGRectMake(SCREEN_WIDTH / 2 - 50 + SCREEN_WIDTH, SCREEN_HEIGHT * 0.24 + 44, 100, 44);
    [UIView animateWithDuration:0.15 animations:^{
        [self.mainView.iconConView setAlpha:0];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.15 animations:^{
            [self.mainView.imgView setAlpha:1];
        }];
    }];
    
    [self beginAnimationWithView:_confirmReset.centerButton delay:0 distance:-SCREEN_WIDTH];
    
    // 登录界面的控件显示
    [self beginAnimationWithView:_loginView.rightUpButton delay:0.3 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.upTextField delay:0.3 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.lineView delay:0.33 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerTextField delay:0.36 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerButton delay:0.39 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_loginView.centerDownButton delay:0.39 distance:-SCREEN_WIDTH];
    //    self.loginView.centerDownButton.frame = CGRectMake(LOGIN_DOWN_X - SCREEN_WIDTH, LOGIN_DOWN_Y, LOGIN_DOWN_WIDTH, LOGIN_DOWN_HEIGHT);
    [self.mainView sendSubviewToBack:_confirmReset];
}

#pragma mark - 下一步
- (void)resetPasswordCenterDownAction:(id)sender
{
    NSString *deviceID = [self getUUID];
    NSString *usingKey = [self getUsingKey];
    
    // 将参数存入字典
    NSMutableDictionary *parmeters = [NSMutableDictionary dictionary];
    [parmeters setObject:deviceID forKey:@"deviceID"];
    [parmeters setObject:usingKey forKey:@"usingKey"];
    [parmeters setObject:self.resetPassword.centerTextField.text forKey:@"password"];
    [parmeters setObject:self.resetPassword.downTextField.text forKey:@"confirmPassword"];
    [parmeters setObject:self.resetPassword.auTextField.text forKey:@"code"];
    [parmeters setObject:self.resetPassword.upTextField.text forKey:@"mobile"];
    NSString * body = [self getFullParmeterWithDic:parmeters];
    [AFNetWorkingYU netWorkWithURL:URL_USER_PASSWORDGET body:body resultBlock:^(id result) {
        if ([result isKindOfClass:[NSDictionary class]]) {
            NSDictionary *dic = (NSDictionary *)result;
            NSString *msg = [dic objectForKey:@"msg"];
            msg = [msg stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [self showAlertWithMessage:msg];
            if ([[dic objectForKey:@"msg"] isEqualToString:@"重置成功"]) {
                [self.mainView bringSubviewToFront:_confirmReset];
                [self.confirmReset.centerButton setFrame:CGRectMake(SCREEN_WIDTH / 2 - 50 + SCREEN_WIDTH, 176, 100, 44)];
                // 注册页面的控件出现
                [UIView animateWithDuration:0.15 animations:^{
                    [self.mainView.iconView setAlpha:0];
                } completion:^(BOOL finished) {
                    [UIView animateWithDuration:0.15 animations:^{
                        [self.mainView.iconConView setAlpha:1];
                    }];
                }];
                [self beginAnimationWithView:_resetPassword.upTextField delay:0.0f distance:-SCREEN_WIDTH];
                [self beginAnimationWithView:_resetPassword.upLine delay:0.03f distance:-SCREEN_WIDTH];
                [self beginAnimationWithView:_resetPassword.centerTextField delay:0.06 distance:-SCREEN_WIDTH];
                [self beginAnimationWithView:_resetPassword.midLine delay:0.09 distance:-SCREEN_WIDTH];
                [self beginAnimationWithView:_resetPassword.downTextField delay:0.12 distance:-SCREEN_WIDTH];
                [self beginAnimationWithView:_resetPassword.downLine delay:0.12 distance:-SCREEN_WIDTH];
                [self beginAnimationWithView:_resetPassword.auTextField delay:0.13 distance:-SCREEN_WIDTH];
                [self beginAnimationWithView:_resetPassword.downButton delay:0.13 distance:-SCREEN_WIDTH];
                [self beginAnimationWithView:_resetPassword.centerButton delay:0.18 distance:-SCREEN_WIDTH];
                [self beginAnimationWithView:_resetPassword.centerDownButton delay:0.18 distance:-SCREEN_WIDTH];
                
                [self beginAnimationWithView:_confirmReset.centerButton delay:0.2 distance:-SCREEN_WIDTH];
            }
        }
        else {
            [self showAlertWithMessage:@"未知错误"];
        }
        // 得到是否注册成功的信息
    }];
}

#pragma mark -
- (void)nextPageButtonAction:(UIButton *)button
{   
    [self.view endEditing:YES];
    // 点击下一步, 先获取输入框的内容
    self.phoneNumber = self.registView.upTextField.text;
    self.password = self.registView.centerTextField.text;
    self.verifyCode = self.registView.downTextField.text;
    
    // 验证输入框输入内容是否符合要求
    BOOL verify = [self verifyRegistMessage];
    if (verify) {
        // 禁止用户在请求数据的时候第二次操作
        UIView *fontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        fontView.backgroundColor = [UIColor whiteColor];
        fontView.alpha = 0.8;
        [self.view addSubview:fontView];
        // 风火轮
        [self.load addLoadView:self.view];
        
        
        
        NSString *approveKey = [self getApproveKey];
        NSString *deviceParam = [self getUsingKey];
        
        // 如果所有信息都符合要求, 进行注册请求
        NSMutableDictionary *parmeters = [self getParmeterDic];
        [parmeters setObject:approveKey forKey:@"approveKey"];
        [parmeters setObject:deviceParam forKey:@"deviceParam"];
        [parmeters setObject:_password forKey:@"password"];
        [parmeters setObject:_verifyCode forKey:@"verifyCode"];
        [parmeters setObject:@"60" forKey:@"validTime"];
        [parmeters setObject:@"true" forKey:@"rememberPassword"];    
        NSString *body = [self getFullParmeterWithDic:parmeters];
        [AFNetWorkingYU netWorkWithURL:@"http://www.isu.so/user/mobi_reg" body:body resultBlock:^(id result) {
            [fontView removeFromSuperview];
            [self.load stopAnimationLoadView];
            
            NSDictionary *dic = (NSDictionary *)result;
            NSString *msg = [dic objectForKey:@"msg"];
            msg = [msg stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [self showAlertWithMessage:msg];
            // 得到是否注册成功的信息
            NSString *success = [NSString stringWithFormat:@"%@",             [dic objectForKey:@"success"]];
            if ([success isEqualToString:@"1"]) {
                
                // 如果注册成功, 把approveKey和deviceParam, 登录状态存储
                [SSKeychain setPassword:approveKey forService:@"com.isuso" account:@"uuid"];
                [SSKeychain setPassword:deviceParam forService:@"com.isuso" account:@"appriveKey"];           
                NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
                [def setObject:@"true" forKey:@"login"];
                
                // 得到用户信息
                [self getUserIdByRequest:approveKey deviceParam:deviceParam];
                
                // 跳转到选择身份页面
                [self identitySelectPage];
                
            }
        }];
        
    }
    
}

#pragma mark - 注册成功后请求用户信息得到id
- (void)getUserIdByRequest:(NSString *)approveKey deviceParam:(NSString *)deviceParam
{
    NSMutableDictionary *parmeter = [NSMutableDictionary dictionary];
    [parmeter setObject:approveKey forKey:@"approveKey"];
    [parmeter setObject:deviceParam forKey:@"deviceParam"];
    NSString *body = [self getFullParmeterWithDic:parmeter];
    [AFNetWorkingYU netWorkWithURL:@"http://www.isu.so/user/mobi_getdetail" body:body resultBlock:^(id result) {
        NSDictionary *resultDic = (NSDictionary *)result;
        NSString *success = [NSString stringWithFormat:@"%@", [resultDic objectForKey:@"success"]];
        if ([success isEqualToString:@"1"]) {
            NSDictionary *obj = [resultDic objectForKey:@"obj"];
            NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
            [def setObject:[obj objectForKey:@"id"] forKey:@"id"];
        }
        
    }];
}

#pragma mark - 注册成功后选择身份页面出来
- (void)identitySelectPage
{
    [self.mainView bringSubviewToFront:_identity];
    // 当前 "注册页面和logo图片" 向左出去, 上传头像按钮显示
    [self beginAnimationWithView:_mainView.imgView delay:0 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_mainView.photoButton delay:0 distance:-SCREEN_WIDTH];
    
    // 注册页面的控件向左飞出去
    _registView.rightUpButton.frame = CGRectMake(REGIST_RIGHT_X - SCREEN_WIDTH, REGIST_RIGHT_Y, REGIST_RIGHT_WIDTH, REGIST_RIGHT_HEIGHT);
    [self beginAnimationWithView:_registView.upTextField delay:0 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.upLine delay:0.03 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.centerTextField delay:0.06 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.downLine delay:0.09 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.downTextField delay:0.12 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.centerButton delay:0.06 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_registView.downButton delay:0.15 distance:-SCREEN_WIDTH];
    self.registView.centerDownButton.frame = CGRectMake(REGIST_DOWN_X - SCREEN_WIDTH, REGIST_DOWN_Y, REGIST_DOWN_WIDTH, REGIST_DOWN_HEIGHT); 
    
    // 注册身份页面的控件逐个儿飞出来
    [self beginAnimationWithView:_identity.upTextField delay:0.3 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_identity.upLine delay:0.33 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_identity.centerTextField delay:0.36 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_identity.stuSuperView delay:0.39 distance:-SCREEN_WIDTH];
    [self beginAnimationWithView:_identity.sexSuperView delay:0.42 distance:-SCREEN_WIDTH];
    self.identity.centerDownButton.frame = CGRectMake(IDENTITY_DOWN_X - SCREEN_WIDTH, IDENTITY_DOWN_Y, IDENTITY_DOWN_WIDTH, IDENTITY_DOWN_HEIGHT);
}

#pragma mark - textfield开始编辑时弹出选择大学视图
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if ([textField.placeholder isEqualToString:@"学  校"]) {
        [self presentViewController:self.collegeRegist animated:YES completion:nil];
    }
}

#pragma mark - 通过协议传值得到选中的大学
- (void)assignCollegeName:(NSString *)name
{
    self.identity.upTextField.text = name;
    
}

#pragma mark - 进入的点击事件
- (void)enterAppAction
{
    
    NSString *approveKey = [GlobalMethod GetIOSUUID];
    NSString *deviceParma = [GlobalMethod getApproveKey];
    NSMutableDictionary *parmater = [NSMutableDictionary dictionary];
    [parmater setObject:approveKey forKey:@"approveKey"];
    [parmater setObject:deviceParma forKey:@"deviceParam"];
    [parmater setObject:self.collegeName forKey:@"school"];
    [parmater setObject:self.name forKey:@"nick"];
    [parmater setObject:self.student forKey:@"role"];
    [parmater setObject:self.sex forKey:@"gender"];
    NSString *body = [self getFullParmeterWithDic:parmater];
    [AFNetWorkingYU netWorkWithURL:URL_USER_INFO_EDIT body:body resultBlock:^(id result) {
        [self.load stopAnimationLoadView];
        self.view.userInteractionEnabled = YES;
        if ([result isKindOfClass:[NSDictionary class]]) {
            
            NSString *str = [result objectForKey:@"msg"];
            str = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            //此时应该插入一个动画 “正在同步服务器，请稍后” ,返回结果显示是否修改成功
            //        [myView removeFromSuperview];
            if ([str isEqualToString:@"编辑成功！"]) {
                
                // 跳转页面
                AppDelegate *appdel = (AppDelegate *)[UIApplication sharedApplication].delegate;
                YRSideViewController *sideV = (YRSideViewController *)appdel.window.rootViewController;
                LeftViewController *leftV = (LeftViewController *)sideV.leftViewController;
                [leftV backRootViewController];
                NavigationViewController *nav = (NavigationViewController *)sideV.rootViewController;
                [[NSNotificationCenter defaultCenter] removeObserver:nav name:@"PUSH" object:nil];
                nav.view = nil;
                [self dismissViewControllerAnimated:YES completion:^{
                    
                }];
                
            }
            else
            {
                [self showAlertWithMessage:@"编辑信息失败"];
            }
            
        }
        else
        {
            //添加无网图
            UIView *fondView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
            [self.view addSubview:fondView];
            [LoadIndicator networkStateNotReachableInView:fondView];
        }
        
    }];
    
}

#pragma mark - 登录点击事件
- (void)loginEnterAction:(UIButton *)button
{
    [self.view endEditing:YES];
    // 获取手机号和密码
    self.phoneNumber = self.loginView.upTextField.text;
    self.password = self.loginView.centerTextField.text;
    // 验证输入是否有误
    BOOL verify = [self verifyLoginMessage];
    if (verify) {
        // 禁止用户在请求数据的时候第二次操作
        UIView *fontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        fontView.backgroundColor = [UIColor whiteColor];
        fontView.alpha = 0.8;
        [self.view addSubview:fontView];
        // 风火轮
        [self.load addLoadView:self.view];
        
        
        NSString *approveKey = [self getApproveKey];
        NSString *deviceParam = [self getUsingKey];
        NSMutableDictionary *parmeters = [NSMutableDictionary dictionary];
        [parmeters setObject:_phoneNumber forKey:@"mobile"];
        [parmeters setObject:_password forKey:@"password"];
        [parmeters setObject:approveKey forKey:@"approveKey"];
        [parmeters setObject:deviceParam forKey:@"deviceParam"];
        [parmeters setObject:@"60" forKey:@"validTime"];
        [parmeters setObject:@"true" forKey:@"rememberPassword"];    
        NSString *body = [self getFullParmeterWithDic:parmeters];
        [AFNetWorkingYU netWorkWithURL:@"http://www.isu.so/user/mobi_login" body:body resultBlock:^(id result) {
            // 请求到数据, 取消风火轮和view
            [fontView removeFromSuperview];
            [self.load stopAnimationLoadView];
            
            // 如果有网,进行页面跳转等操作
            if ([result isKindOfClass:[NSDictionary class]]) {
                NSDictionary *dic = (NSDictionary *)result;
                // 提示信息
                NSString *msg = [dic objectForKey:@"msg"];
                msg = [msg stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                
                // 得到是否登录成功的信息
                NSString *success = [NSString stringWithFormat:@"%@",[dic objectForKey:@"success"]];
                if ([success isEqualToString:@"1"]) {
                    // 如果登录成功, 把approveKey和deviceParam, 登录状态存储
                    [SSKeychain setPassword:approveKey forService:@"com.isuso" account:@"uuid"];
                    [SSKeychain setPassword:deviceParam forService:@"com.isuso" account:@"appriveKey"];
                    NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
                    [def setObject:@"true" forKey:@"login"];
                    [def synchronize];
                    // 得到userID
                    
                    NSDictionary *obj = [dic objectForKey:@"obj"];
                    [def setObject:[obj objectForKey:@"id"] forKey:@"id"];
                    
                    AppDelegate *appdel = (AppDelegate *)[UIApplication sharedApplication].delegate;
                    YRSideViewController *sideV = (YRSideViewController *)appdel.window.rootViewController;
                    LeftViewController *leftV = (LeftViewController *)sideV.leftViewController;
                    [leftV backRootViewController];
                    NavigationViewController *nav = (NavigationViewController *)sideV.rootViewController;
                    [[NSNotificationCenter defaultCenter] removeObserver:nav name:@"PUSH" object:nil];
                    nav.view = nil;
                    [self dismissViewControllerAnimated:YES completion:^{
                        
                    }];
                    
                } else {
                    [self showAlertWithMessage:msg];
                }
            }
            else {
                [self showAlertWithMessage:@"网络错误"];
            }
        }];
    }
    
    
}

#pragma mark - 获取验证码点击事件
- (void)verifyButtonAction:(UIButton *)button
{
    self.phoneNumber = _registView.upTextField.text;
    // 将参数存入字典
    NSMutableDictionary *parmeters = [self getParmeterDic];
    // 获得拼接后的参数字符串
    NSString *body = [self getFullParmeterWithDic:parmeters];
    // 发送请求
    [AFNetWorkingYU netWorkWithURL:@"http://www.isu.so/sms_api/req" body:body resultBlock:^(id result) {
        NSDictionary *resultDic = (NSDictionary *)result;
        NSString *msg = [resultDic objectForKey:@"msg"];
        if ([msg isEqualToString:@"success"]) {
            // 获取验证码成功后先取消点击事件
            [_registView.downButton removeTarget:self action:@selector(verifyButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            // 在button上面放一个倒计时的label, 防止读秒的时候一闪一闪
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _registView.downButton.frame.size.width, _registView.downButton.frame.size.height)];
            [label setTextColor:TEXTGREENCOLOR];
            [label setFont:BOLDENGLISH_FONT(14.0)];
            [label setTextAlignment:NSTextAlignmentRight];
            [_registView.downButton addSubview:label];
            // 倒计时
            _timeCount = 45;
            _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDownTime:) userInfo:label repeats:YES];
        } else {
            [self showAlertWithMessage:msg];
            
        }
        
    }];
}

#pragma mark - 封装参数
- (NSString *)getFullParmeterWithDic:(NSDictionary *)dic
{
    NSString *str = @"";
    for (NSString *key in dic) {
        if ([str length] == 0) {
            str = [NSString stringWithFormat:@"%@=%@", key, [dic objectForKey:key]];
        } else {
            str = [NSString stringWithFormat:@"%@&%@=%@", str, key, [dic objectForKey:key]];
        }
    }
    return str;
    
}

#pragma mark - 将主要参数封装到字典中, 用于post请求body的拼接
- (NSMutableDictionary *)getParmeterDic
{
    // 获得approveKey, deviceParam
    NSString *deviceID = [self getUUID];
    NSString *usingKey = [self getUsingKey];
    
    // 将参数存入字典
    NSMutableDictionary *parmeters = [NSMutableDictionary dictionary];  
    [parmeters setObject:_phoneNumber forKey:@"mobile"];
    [parmeters setObject:deviceID forKey:@"deviceID"];
    [parmeters setObject:usingKey forKey:@"usingKey"];
    
    return parmeters;
}

#pragma mark - 获得approveKey
- (NSString *)getApproveKey
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYYMMDDhhmmssSSS"];
    NSString *date = [formatter stringFromDate:[NSDate date]];
    NSString *approveKey = [GlobalMethod GetIOSUUID];
    // 获得NSDate
    approveKey = [NSString stringWithFormat:@"%@%@", date, approveKey];
    approveKey = [GlobalMethod md5:approveKey];
    approveKey = [approveKey lowercaseString];
    
    return approveKey;
}

#pragma mark - 获得deviceID
- (NSString *)getUUID
{
    NSString *uuid = [UIDevice currentDevice].identifierForVendor.UUIDString;
    uuid = [uuid stringByReplacingOccurrencesOfString:@"-" withString:@""];
    uuid = [uuid lowercaseString];
    return uuid;
}

#pragma mark - 获得usingKey
- (NSString *)getUsingKey
{
    NSString * usingKey = [self getUUID];
    usingKey = [GlobalMethod md5:[NSString stringWithFormat:@"douhao%@", usingKey]];
    usingKey = [usingKey lowercaseString];
    return usingKey;
}

#pragma mark - 动画切换效果
- (void)beginAnimationWithView:(UIView *)view delay:(CGFloat)delay distance:(CGFloat)distance
{
    [UIView beginAnimations:@"lxb" context:nil];
    [UIView setAnimationDelay:delay];
    [UIView setAnimationDuration:0.3];
    view.frame = CGRectMake(view.frame.origin.x + distance, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
    [UIView commitAnimations];
}

#pragma mark - 选择相册
- (void)pickImageFromAlbum
{
    
    // 从相册中选取
    
    if ([self isPhotoLibraryAvailable]) {
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
        [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
        controller.mediaTypes = mediaTypes;
        controller.delegate = self;
        [self presentViewController:controller
                           animated:YES
                         completion:^(void){
                             NSLog(@"Picker View Controller is presented");
                         }];
        
        
    }
    
}

#pragma mark - 选择相机
- (void)pickImageFromCamera
{
    
    
    // 拍照
    if ([self isCameraAvailable] && [self doesCameraSupportTakingPhotos]) {
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        controller.sourceType = UIImagePickerControllerSourceTypeCamera;
        if ([self isFrontCameraAvailable]) {
            controller.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        }
        NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
        [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
        controller.mediaTypes = mediaTypes;
        controller.delegate = self;
        [self presentViewController:controller
                           animated:YES
                         completion:^(void){
                             NSLog(@"Picker View Controller is presented");
                         }];
        
        
    }
    
    
}

#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^() {
        UIImage *portraitImg = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        portraitImg = [self imageByScalingToMaxSize:portraitImg];
        // 裁剪
        VPImageCropperViewController *imgEditorVC = [[VPImageCropperViewController alloc] initWithImage:portraitImg cropFrame:CGRectMake(0, 100.0f, self.view.frame.size.width, self.view.frame.size.width) limitScaleRatio:3.0];
        imgEditorVC.delegate = self;
        [self presentViewController:imgEditorVC animated:YES completion:^{
            
            self.dic = [NSDictionary dictionaryWithDictionary:info];
            
        }];
        
        
    }];
}

//上传头像
- (void)transferMyDataToServer:(UIButton *)button
{
    self.collegeName = _identity.upTextField.text;
    self.name = _identity.centerTextField.text;
    BOOL verify = [self verifyIdentityMessage];
    if (verify) {
        // 风火轮, 用户交互关闭
        [self.load addLoadView:self.view];
        self.view.userInteractionEnabled = NO;
        
        NSLog(@"myphotoName2 = %@",self.myPhotoName);
        
        // 上传头像
        NSString *myPicture = [self.myPhotoName substringFromIndex:16];
        NSLog(@"图片网址3 :%@", myPicture);
        NSString *key = [GlobalMethod getApproveKey];
        NSString *device = [GlobalMethod GetIOSUUID];
        NSString *str =[NSString stringWithFormat:@"approveKey=%@&deviceParam=%@&", device, key];
        NSString *getUrl = [NSString stringWithFormat:@"%@?%@img=%@", URL_USER_INFO_EDIT, str,myPicture];
        
        
        [AFNetWorkingYU netWorkingHanderGetGataWithUrl:getUrl resultBlock:^(id result) {
            if ([result isKindOfClass:[NSDictionary class]]) {
                NSString *str = [result objectForKey:@"msg"];
                str = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                //此时应该插入一个动画 “正在同步服务器，请稍后” ,返回结果显示是否修改成功
                if ([str isEqualToString:@"编辑成功！"]) {
                    // 上传个人信息
                    NSLog(@"上传成功!!!!!!");
                    [self enterAppAction];
                    
                } else
                {
                    // 上传失败提示
                    [self showAlertWithMessage:str];
                }
            }
            else {
                UIView *fondView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
                [self.view addSubview:fondView];
                [LoadIndicator networkStateNotReachableInView:fondView];
                
            }
            
        }];
    }
    
}

//完成剪切图片 上传服务器（代理方法）
#pragma mark VPImageCropperDelegate
- (void)imageCropper:(VPImageCropperViewController *)cropperViewController didFinished:(UIImage *)editedImage {
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    view.backgroundColor = [UIColor grayColor];
    view.alpha = 0.5;
    [self.view addSubview:view];
    //用户交互关闭
    [self.load addLoadView:self.view];
    self.view.userInteractionEnabled = NO;
    
    //剪切图片后放到头像上
    [self.mainView.photoButton setBackgroundImage:editedImage forState:UIControlStateNormal];
    [self.mainView.photoButton setTitle:@"" forState:UIControlStateNormal];
    
    [UIView animateWithDuration:0.3 animations:^{
        self.mainView.photoChildView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 88);
        [self.mainView.blackView removeFromSuperview];
    }];
    
    //点击确定后让剪辑器消失
    [cropperViewController dismissViewControllerAnimated:YES completion:^{
        
        
        //上传图片
        NSString *type = [self.dic objectForKey:UIImagePickerControllerMediaType];
        
        //当选择的类型是图片
        if ([type isEqualToString:@"public.image"])
        {
            
            @autoreleasepool {
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                    NSData *data;
                    
                    UIImage * oImage = [self fixOrientation:editedImage];
                    data = UIImageJPEGRepresentation(oImage, 0.005);
                    
                    UIImage * newImage = [UIImage imageWithData:data];
                    data = UIImagePNGRepresentation(newImage);
                    
//                    NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
                    
                    
                    
//                    //得到选择后沙盒中图片的完整路径
//                    NSString * filePath = [[NSString alloc]initWithFormat:@"%@/image1.png",DocumentsPath];
//                    [data writeToFile:filePath atomically:YES];
//                    if (data != nil) {
                        dispatch_async(dispatch_get_main_queue(), ^{
                            //                        NSData * imageData = [NSData dataWithContentsOfFile:filePath];
                            [UpLoadMyPhoto uploadWithImageName:@"iPhoneImage" imageData:data finish:^(NSData *resultData) {
                                if ([resultData isKindOfClass:[NSData class]]) {
                                    
                                    
                                    NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:resultData options:NSJSONReadingMutableContainers error:nil];
                                    NSLog(@"%@",dic);
                                    NSArray *array = [dic objectForKey:@"avatarUrls"];
                                    NSString *myPic = [array firstObject];
                                    NSLog(@"tupianmingcheng11 = %@",myPic);
                                    self.myPhotoName = myPic;
                                    NSLog(@"上传图片 = %@",[dic objectForKey:@"msg"]);
                                    self.view.userInteractionEnabled = YES;
                                    [view removeFromSuperview];
                                    [self.load stopAnimationLoadView];
                                    [self showAlertWithMessage:@"选择头像成功"];
                                    
                                }
                                else
                                {
                                    UIView *fondView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
                                    [self.view addSubview:fondView];
                                    [LoadIndicator networkStateNotReachableInView:fondView];
                                    
                                }
                            }];
                        });
//                    }
                });
            }
            
        }
    }];
}

//点击取消按钮，取消剪辑图片（代理方法）
- (void)imageCropperDidCancel:(VPImageCropperViewController *)cropperViewController {
    //点击取消后让剪辑器消失
    
    [UIView animateWithDuration:0.3 animations:^{
        self.mainView.photoChildView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 88);
        [self.mainView.blackView removeFromSuperview];
    }];
    [cropperViewController dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (UIImage *)fixOrientation:(UIImage *)aImage {
    
    // No-op if the orientation is already correct
    if (aImage.imageOrientation == UIImageOrientationUp)
        return aImage;
    
    // We need to calculate the proper transformation to make the image upright.
    // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
    CGAffineTransform transform = CGAffineTransformIdentity;
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationDown:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);
            transform = CGAffineTransformRotate(transform, M_PI);
            break;
            
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformRotate(transform, M_PI_2);
            break;
            
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);
            transform = CGAffineTransformRotate(transform, -M_PI_2);
            break;
        default:
            break;
    }
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationUpMirrored:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
            
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
        default:
            break;
    }
    
    // Now we draw the underlying CGImage into a new context, applying the transform
    // calculated above.
    CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
                                             CGImageGetBitsPerComponent(aImage.CGImage), 0,
                                             CGImageGetColorSpace(aImage.CGImage),
                                             CGImageGetBitmapInfo(aImage.CGImage));
    CGContextConcatCTM(ctx, transform);
    switch (aImage.imageOrientation) {
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            // Grr...
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);
            break;
            
        default:
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);
            break;
    }
    
    // And now we just create a new UIImage from the drawing context
    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
    UIImage *img = [UIImage imageWithCGImage:cgimg];
    CGContextRelease(ctx);
    CGImageRelease(cgimg);
    return img;
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^(){
        
        
        [UIView animateWithDuration:0.3 animations:^{
            self.mainView.photoChildView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 88);
            [self.mainView.blackView removeFromSuperview];
        }];
    }];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
}
//uiimagepickerController的代理方法
#pragma mark camera utility
//是否允许访问相册
- (BOOL) isCameraAvailable{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isRearCameraAvailable{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
}

- (BOOL) isFrontCameraAvailable {
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
}

- (BOOL) doesCameraSupportTakingPhotos {
    return [self cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isPhotoLibraryAvailable{
    return [UIImagePickerController isSourceTypeAvailable:
            UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickVideosFromPhotoLibrary{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickPhotosFromPhotoLibrary{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

- (BOOL) cameraSupportsMedia:(NSString *)paramMediaType sourceType:(UIImagePickerControllerSourceType)paramSourceType{
    __block BOOL result = NO;
    if ([paramMediaType length] == 0) {
        return NO;
    }
    NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:paramSourceType];
    [availableMediaTypes enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
        NSString *mediaType = (NSString *)obj;
        if ([mediaType isEqualToString:paramMediaType]){
            result = YES;
            *stop= YES;
        }
    }];
    return result;
}

#pragma mark image scale utility 图片的缩放功能
- (UIImage *)imageByScalingToMaxSize:(UIImage *)sourceImage {
    if (sourceImage.size.width < ORIGINAL_MAX_WIDTH) return sourceImage;
    CGFloat btWidth = 0.0f;
    CGFloat btHeight = 0.0f;
    if (sourceImage.size.width > sourceImage.size.height) {
        btHeight = ORIGINAL_MAX_WIDTH;
        btWidth = sourceImage.size.width * (ORIGINAL_MAX_WIDTH / sourceImage.size.height);
    } else {
        btWidth = ORIGINAL_MAX_WIDTH;
        btHeight = sourceImage.size.height * (ORIGINAL_MAX_WIDTH / sourceImage.size.width);
    }
    CGSize targetSize = CGSizeMake(btWidth, btHeight);
    return [self imageByScalingAndCroppingForSourceImage:sourceImage targetSize:targetSize];
}

- (UIImage *)imageByScalingAndCroppingForSourceImage:(UIImage *)sourceImage targetSize:(CGSize)targetSize {
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor; // scale to fit height
        else
            scaleFactor = heightFactor; // scale to fit width
        scaledWidth  = width * scaleFactor;
        scaledHeight = height * scaleFactor;
        
        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else
            if (widthFactor < heightFactor)
            {
                thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
            }
    }
    UIGraphicsBeginImageContext(targetSize); // this will crop
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width  = scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil) NSLog(@"could not scale image");
    
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    return newImage;
}

#pragma mark - 验证输入信息是否符合注册规定
- (BOOL)verifyRegistMessage
{
    if ([_phoneNumber isEqualToString:@""]) {
        [self showAlertWithMessage:@"请输入手机号"];
        return NO;
    }
    if (_phoneNumber.length != 11) {
        [self showAlertWithMessage:@"请输入11位手机号"];
        return NO;
    }
    if ([_password isEqualToString:@""]) {
        [self showAlertWithMessage:@"请输入密码"];
        return NO;
    }
    if (_password.length < 6) {
        [self showAlertWithMessage:@"密码不能低于6位"];
        return NO;
    }
    if ([_verifyCode isEqualToString:@""]) {
        [self showAlertWithMessage:@"请输入验证码"];
        return NO;
    }
    return YES;
}

#pragma mark - 验证是否选择了身份信息
- (BOOL)verifyIdentityMessage
{
    if (![_mainView.photoButton.currentTitle isEqualToString:@""]) {
        [self showAlertWithMessage:@"请选择头像"];
        return NO;
    }
    if ([_collegeName isEqualToString:@""] || _collegeName == nil) {
        [self showAlertWithMessage:@"请选择学校"];
        return NO;
    }
    if ([_name isEqualToString:@""] || _name == nil) {
        [self showAlertWithMessage:@"请输入姓名"];
        return NO;
    }
    if (_name.length > 12) {
        [self showAlertWithMessage:@"最多输入6个汉字"];
        return NO;
    }
    return YES;
}

#pragma mark - 验证输入信息是否符合登录规定
- (BOOL)verifyLoginMessage
{
    if ([_phoneNumber isEqualToString:@""]) {
        [self showAlertWithMessage:@"请输入手机号"];
        return NO;
    }
    if (_phoneNumber.length != 11) {
        [self showAlertWithMessage:@"请输入11位手机号"];
        return NO;
    }
    if ([_password isEqualToString:@""]) {
        [self showAlertWithMessage:@"请输入密码"];
        return NO;
    }
    return YES;
}

#pragma mark - 提示框
- (void)showAlertWithMessage:(NSString *)message
{
    self.alert = [[UIAlertView alloc] initWithTitle:nil message:message delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [_alert show];
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(dismissAlert) userInfo:nil repeats:NO];
}

- (void)dismissAlert
{
    [_alert dismissWithClickedButtonIndex:0 animated:YES];
}

#pragma mark - 点击选择身份类型的时候得到选中的title
- (void)getIdentityType:(NSNotification *)notify
{
    self.student = [[notify userInfo] objectForKey:@"student"];
    self.sex = [[notify userInfo] objectForKey:@"sex"];
}


#pragma mark - 
- (void)countDownTime:(NSTimer *)timer
{
    // 删除button的title
    [_registView.downButton setTitle:@"" forState:UIControlStateNormal];
    UILabel *label = timer.userInfo;
    // 倒计时
    [label setText:[NSString stringWithFormat:@"%d", _timeCount]];
    if (_timeCount == 0) {
        [label removeFromSuperview];
        [_timer invalidate];
        [self.registView.downButton setTitle:@"重新发送 >" forState:UIControlStateNormal];
        [self.registView.downButton addTarget:self action:@selector(verifyButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    _timeCount--;
    
}

- (void)resetCountDown
{
    [self.resetPassword.downButton setEnabled:NO];
    if (!self.authLabel) {
        self.authLabel = [[UILabel alloc] init];
        [_authLabel setTextColor:TEXTGREENCOLOR];
        [_authLabel setTextAlignment:NSTextAlignmentCenter];
        [self.resetPassword addSubview:_authLabel];
        [self.resetPassword bringSubviewToFront:_authLabel];
        [self.authLabel setBackgroundColor:[UIColor whiteColor]];
    }
    CGRect rect = self.resetPassword.downButton.frame;
    [_authLabel setFrame:CGRectMake(rect.origin.x, rect.origin.y + 3, rect.size.width, rect.size.height - 6)];
    [_authLabel setText:[NSString stringWithFormat:@"%d", _timeCount]];
    if (_timeCount == 0) {
        [_timer invalidate];
        [self.resetPassword.downButton setTitle:@"重新发送 >" forState:UIControlStateNormal];
        [self.resetPassword.downButton setEnabled:YES];
        [self.authLabel setFrame:CGRectZero];
    }
    _timeCount--;
}

#pragma mark - 得到登录后要显示的页面
- (YRSideViewController *)getHomePage
{
    NDetailListViewController *detail = [[NDetailListViewController alloc] init];
    NavigationViewController *nav = [[NavigationViewController alloc] initWithRootViewController:detail];
    nav.rootController = detail;
    nav.navigationBar.translucent = NO;
    nav.navigationBar.hidden = YES;
    
    
    LeftViewController *leftViewController=[LeftViewController share];
    
    YRSideViewController *sideViewController = [YRSideViewController share];
    sideViewController.rootViewController = nav;
    
    sideViewController.leftViewController = leftViewController;
    sideViewController.needSwipeShowMenu = YES;
    return sideViewController;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
